﻿<DemoPageSectionComponent Id="DataGrid-DataBinding-LargeDataSource" ShowHorizontalScrollBar="true">
    @inherits OwningComponentBase
    @inject Microsoft.Extensions.Configuration.IConfiguration Configuration

    <DataProviderAccessAreaContainer DataProvider="@RentInfoDataProvider">
        <DxDataGrid Data="Data"
                    PageSize="10"
                    ShowFilterRow="true"
                    KeyFieldName="@nameof(AreaRentInfo.Oid)">
            <DxDataGridColumn Field="@nameof(AreaRentInfo.State)"></DxDataGridColumn>
            <DxDataGridColumn Field="@nameof(AreaRentInfo.Area)"></DxDataGridColumn>
            <DxDataGridColumn Field="@nameof(AreaRentInfo.City)" Caption="County"></DxDataGridColumn>
            <DxDataGridColumn Field="@nameof(AreaRentInfo.Name)" Caption="Location"></DxDataGridColumn>
            <DxDataGridSpinEditColumn Field="@nameof(AreaRentInfo.Year)"></DxDataGridSpinEditColumn>
            <DxDataGridSpinEditColumn Field="@nameof(AreaRentInfo.Bedrooms)"></DxDataGridSpinEditColumn>
            <DxDataGridSpinEditColumn Field="@nameof(AreaRentInfo.Rent)">
                <DisplayTemplate>
                    @(((context as AreaRentInfo).Rent).ToString("C2"))
                </DisplayTemplate>
            </DxDataGridSpinEditColumn>
            <DxDataGridSpinEditColumn Field="@nameof(AreaRentInfo.Population)">
                <DisplayTemplate>
                    @(((context as AreaRentInfo).Population).ToString("#,0"))
                </DisplayTemplate>
            </DxDataGridSpinEditColumn>
        </DxDataGrid>
    </DataProviderAccessAreaContainer>
    @code {
        IRentInfoDataProvider RentInfoDataProvider { get; set; }
        RentInfoDataService RentInfoDataService { get; set; }

        IEnumerable<AreaRentInfo> Data { get; set; }

        protected override void OnInitialized() {
            // Refer to https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.components.owningcomponentbase
            RentInfoDataProvider = ScopedServices.GetRequiredService<IRentInfoDataProvider>();
            RentInfoDataService = ScopedServices.GetRequiredService<RentInfoDataService>();

            var connectionString = ConnectionStringUtils.GetGridLargeDataConnectionString(Configuration);
            if(string.IsNullOrEmpty(connectionString)) return;

            Data = RentInfoDataService.GetAreaRentInfo();
        }
    }
</DemoPageSectionComponent>
